package org.jsbd.boss.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.domian.statistics.MarkImsiCountBean;
import org.jsbd.boss.domian.statistics.MarkImsiCountVO;
import org.jsbd.boss.service.IMarkImsiCountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/mark/imsi/count")
public class MarkImsiCountController {

	private static final Logger logger = LoggerFactory.getLogger(MarkImsiCountController.class);

	@Resource
	private IMarkImsiCountService markImsiCountService;

	/**
	 * 当月新增于当月留存出现次数计数
	 * 
	 * @return
	 */
	@RequestMapping(value = "/currentMonthList")
	public String currentMonthList() {
		return "markImsiCount/currentMonthList";
	}

	/**
	 * 
	 * 当月新增于当月留存出现次数计数数据
	 * 
	 * @param model
	 * @param markImsiCountVO
	 * @return
	 */
	@RequestMapping(value = "/currentMonthListJson", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> currentMonthListJson(DataGridModel page, MarkImsiCountVO markImsiCountVO) {
		String startTime = markImsiCountVO.getStartTime();
		String endTime = markImsiCountVO.getEndTime();
		if (!StringUtils.isBlank(startTime)) {
			markImsiCountVO.setStartTime(startTime.replaceAll("-", ""));
		}
		if (!StringUtils.isBlank(endTime)) {
			markImsiCountVO.setEndTime(endTime.replaceAll("-", ""));
		}
		return markImsiCountService.findCurrentMonth(page, markImsiCountVO);
	}

	/**
	 * 
	 * 当月新增于当月留存出现次数计数数据详情
	 * 
	 * @param model
	 * @param markImsiCountVO
	 * @return
	 */
	@RequestMapping(value = "/getCurrentMonthDetail")
	public String getCurrentMonthDetail(Model model, MarkImsiCountVO markImsiCountVO) {
		List<MarkImsiCountBean> list = markImsiCountService.getCurrentMonthDetail(markImsiCountVO);
		model.addAttribute("list", list);
		return "markImsiCount/currentMonthDetail";
	}

	/**
	 * 当月新增于次月留存出现次数计数
	 * 
	 * @return
	 */
	@RequestMapping(value = "/nextMonthList")
	public String nextMonthList() {
		return "markImsiCount/nextMonthList";
	}

	/**
	 * 
	 * 当月新增于次月留存出现次数计数数据
	 * 
	 * @param model
	 * @param markImsiCountVO
	 * @return
	 */
	@RequestMapping(value = "/nextMonthListJson", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> nextMonthListJson(DataGridModel page, MarkImsiCountVO markImsiCountVO) {
		String startTime = markImsiCountVO.getStartTime();
		String endTime = markImsiCountVO.getEndTime();
		if (!StringUtils.isBlank(startTime)) {
			markImsiCountVO.setStartTime(startTime.replaceAll("-", ""));
		}
		if (!StringUtils.isBlank(endTime)) {
			markImsiCountVO.setEndTime(endTime.replaceAll("-", ""));
		}
		return markImsiCountService.findNextMonth(page, markImsiCountVO);
	}

	/**
	 * 
	 * 当月新增于次月留存出现次数计数数据详情
	 * 
	 * @param model
	 * @param markImsiCountVO
	 * @return
	 */
	@RequestMapping(value = "/getNextMonthDetail")
	public String getNextMonthDetail(Model model, MarkImsiCountVO markImsiCountVO) {
		List<MarkImsiCountBean> list = markImsiCountService.getNextMonthDetail(markImsiCountVO);
		model.addAttribute("list", list);
		return "markImsiCount/nextMonthDetail";
	}

}
